<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QGraphicsEffect Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QGraphicsEffect Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QGraphicsEffect class is the base class for all graphics
effects. <a href="#details">More...</a></p>

<p>Inherits <a href="qobject.html">QObject</a>.</p><p>Inherited by <a href="qgraphicsblureffect.html">QGraphicsBlurEffect</a>, <a href="qgraphicscolorizeeffect.html">QGraphicsColorizeEffect</a>, <a href="qgraphicsdropshadoweffect.html">QGraphicsDropShadowEffect</a> and <a href="qgraphicsopacityeffect.html">QGraphicsOpacityEffect</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qgraphicseffect.html#ChangeFlag-enum">ChangeFlag</a></b> { SourceAttached, SourceDetached, SourceBoundingRectChanged, SourceInvalidated }</li><li><div class="fn" />class <b><a href="qgraphicseffect-changeflags.html">ChangeFlags</a></b></li><li><div class="fn" />enum <b><a href="qgraphicseffect.html#PixmapPadMode-enum">PixmapPadMode</a></b> { NoPad, PadToTransparentBorder, PadToEffectiveBoundingRect }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qgraphicseffect.html#QGraphicsEffect">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />QRectF <b><a href="qgraphicseffect.html#boundingRect">boundingRect</a></b> (<i>self</i>)</li><li><div class="fn" />QRectF <b><a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a></b> (<i>self</i>, QRectF&#160;<i>sourceRect</i>)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#draw">draw</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#drawSource">drawSource</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>)</li><li><div class="fn" />bool <b><a href="qgraphicseffect.html#isEnabled">isEnabled</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#setEnabled">setEnabled</a></b> (<i>self</i>, bool&#160;<i>enable</i>)</li><li><div class="fn" />QRectF <b><a href="qgraphicseffect.html#sourceBoundingRect">sourceBoundingRect</a></b> (<i>self</i>, Qt.CoordinateSystem&#160;<i>system</i>&#160;=&#160;Qt.LogicalCoordinates)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#sourceChanged">sourceChanged</a></b> (<i>self</i>, ChangeFlags&#160;<i>flags</i>)</li><li><div class="fn" />bool <b><a href="qgraphicseffect.html#sourceIsPixmap">sourceIsPixmap</a></b> (<i>self</i>)</li><li><div class="fn" />(QPixmap, QPoint&#160;<i>offset</i>) <b><a href="qgraphicseffect.html#sourcePixmap">sourcePixmap</a></b> (<i>self</i>, Qt.CoordinateSystem&#160;<i>system</i>&#160;=&#160;Qt.LogicalCoordinates, PixmapPadMode&#160;<i>mode</i>&#160;=&#160;QGraphicsEffect.PadToEffectiveBoundingRect)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#update">update</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qgraphicseffect.html#enabledChanged">enabledChanged</a></b> (bool)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QGraphicsEffect class is the base class for all graphics
effects.</p>
<p>Effects alter the appearance of elements by hooking into the
rendering pipeline and operating between the source (e.g., a
<a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>) and the
destination device (e.g., <a href="qgraphicsview.html">QGraphicsView</a>'s viewport). Effects can be
disabled by calling setEnabled(false). If effects are disabled, the
source is rendered directly.</p>
<p>To add a visual effect to a <a href="qgraphicsitem.html">QGraphicsItem</a>, for example, you can use
one of the standard effects, or alternately, create your own effect
by creating a subclass of QGraphicsEffect. The effect can then be
installed on the item using <a href="qgraphicsitem.html#setGraphicsEffect">QGraphicsItem.setGraphicsEffect</a>().</p>
<p>Qt provides the following standard effects:</p>
<ul>
<li><a href="qgraphicsblureffect.html">QGraphicsBlurEffect</a> -
blurs the item by a given radius</li>
<li><a href="qgraphicsdropshadoweffect.html">QGraphicsDropShadowEffect</a> -
renders a dropshadow behind the item</li>
<li><a href="qgraphicscolorizeeffect.html">QGraphicsColorizeEffect</a> -
renders the item in shades of any given color</li>
<li><a href="qgraphicsopacityeffect.html">QGraphicsOpacityEffect</a> - renders
the item with an opacity</li>
</ul>
<table class="generic">
<tr class="odd" valign="top">
<td colspan="2">
<p class="centerAlign"><img alt="" src="images/graphicseffect-plain.png" /></p>
</td>
</tr>
<tr class="even" valign="top">
<td>
<p class="centerAlign"><img alt="" src="images/graphicseffect-blur.png" /></p>
</td>
<td>
<p class="centerAlign"><img alt="" src="images/graphicseffect-colorize.png" /></p>
</td>
</tr>
<tr class="odd" valign="top">
<td>
<p class="centerAlign"><img alt="" src="images/graphicseffect-opacity.png" /></p>
</td>
<td>
<p class="centerAlign"><img alt="" src="images/graphicseffect-drop-shadow.png" /></p>
</td>
</tr>
</table>
<p class="centerAlign"><img alt="" src="images/graphicseffect-widget.png" /></p>
<p>For more information on how to use each effect, refer to the
specific effect's documentation.</p>
<p>To create your own custom effect, create a subclass of
QGraphicsEffect (or any other existing effects) and reimplement the
virtual function <a href="qgraphicseffect.html#draw">draw</a>().
This function is called whenever the effect needs to redraw. The
<a href="qgraphicseffect.html#draw">draw</a>() function takes the
painter with which to draw as an argument. For more information,
refer to the documenation for <a href="qgraphicseffect.html#draw">draw</a>(). In the <a href="qgraphicseffect.html#draw">draw</a>() function you can call
<a href="qgraphicseffect.html#sourcePixmap">sourcePixmap</a>() to
get a pixmap of the graphics effect source which you can then
process.</p>
<p>If your effect changes, use <a href="qgraphicseffect.html#update">update</a>() to request for a redraw.
If your custom effect changes the bounding rectangle of the source,
e.g., a radial glow effect may need to apply an extra margin, you
can reimplement the virtual <a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a>()
function, and call <a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a>()
to notify the framework whenever this rectangle changes. The
virtual <a href="qgraphicseffect.html#sourceChanged">sourceChanged</a>() function
is called to notify the effects that the source has changed in some
way - e.g., if the source is a <a href="qgraphicsrectitem.html">QGraphicsRectItem</a> and its rectangle
parameters have changed.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="ChangeFlag-enum" />QGraphicsEffect.ChangeFlag</h3><p>This enum describes what has changed in
QGraphicsEffectSource.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QGraphicsEffect.SourceAttached</tt></td>
<td class="topAlign"><tt>0x1</tt></td>
<td class="topAlign">The effect is installed on a source.</td>
</tr>
<tr>
<td class="topAlign"><tt>QGraphicsEffect.SourceDetached</tt></td>
<td class="topAlign"><tt>0x2</tt></td>
<td class="topAlign">The effect is uninstalled on a source.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QGraphicsEffect.SourceBoundingRectChanged</tt></td>
<td class="topAlign"><tt>0x4</tt></td>
<td class="topAlign">The bounding rect of the source has
changed.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QGraphicsEffect.SourceInvalidated</tt></td>
<td class="topAlign"><tt>0x8</tt></td>
<td class="topAlign">The visual appearance of the source has
changed.</td>
</tr>
</table>
<p>The ChangeFlags type is a typedef for <a href="qflags.html">QFlags</a>&lt;ChangeFlag&gt;. It stores an OR
combination of ChangeFlag values.</p>


<h3 class="fn"><a name="PixmapPadMode-enum" />QGraphicsEffect.PixmapPadMode</h3><p>This enum describes how the pixmap returned from sourcePixmap
should be padded.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QGraphicsEffect.NoPad</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">The pixmap should not receive any additional
padding.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QGraphicsEffect.PadToTransparentBorder</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">The pixmap should be padded to ensure it has a
completely transparent border.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QGraphicsEffect.PadToEffectiveBoundingRect</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">The pixmap should be padded to match the
effective bounding rectangle of the effect.</td>
</tr>
</table>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QGraphicsEffect" />QGraphicsEffect.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new <a href="qgraphicseffect.html">QGraphicsEffect</a> instance having the
specified <i>parent</i>.</p>


<h3 class="fn"><a name="boundingRect" /><a href="qrectf.html">QRectF</a> QGraphicsEffect.boundingRect (<i>self</i>)</h3><p>Returns the effective bounding rectangle for this effect, i.e.,
the bounding rectangle of the source in device coordinates,
adjusted by any margins applied by the effect itself.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a>() and
<a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a>().</p>


<h3 class="fn"><a name="boundingRectFor" /><a href="qrectf.html">QRectF</a> QGraphicsEffect.boundingRectFor (<i>self</i>, <a href="qrectf.html">QRectF</a>&#160;<i>sourceRect</i>)</h3><p>Returns the effective bounding rectangle for this effect, given
the provided <i>rect</i> in the device coordinates. When writing
you own custom effect, you must call <a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a>()
whenever any parameters are changed that may cause this this
function to return a different value.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#sourceBoundingRect">sourceBoundingRect</a>().</p>


<h3 class="fn"><a name="draw" />QGraphicsEffect.draw (<i>self</i>, <a href="qpainter.html">QPainter</a>&#160;<i>painter</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>This pure virtual function draws the effect and is called
whenever the source needs to be drawn.</p>
<p>Reimplement this function in a <a href="qgraphicseffect.html">QGraphicsEffect</a> subclass to provide the
effect's drawing implementation, using <i>painter</i>.</p>
<p>For example:</p>
<pre class="cpp">
 MyGraphicsEffect<span class="operator">.</span>draw(<span class="type"><a href="qpainter.html">QPainter</a></span> <span class="operator">*</span>painter)
 {
     <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
     <span class="type"><a href="qpoint.html">QPoint</a></span> offset;
     <span class="keyword">if</span> (sourceIsPixmap()) {
         <span class="comment">// No point in drawing in device coordinates (pixmap will be scaled anyways).</span>
         <span class="keyword">const</span> <span class="type"><a href="qpixmap.html">QPixmap</a></span> pixmap <span class="operator">=</span> sourcePixmap(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>LogicalCoordinates<span class="operator">,</span> <span class="operator">&amp;</span>offset);
         <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
         painter<span class="operator">-</span><span class="operator">&gt;</span>drawPixmap(offset<span class="operator">,</span> pixmap);
     } <span class="keyword">else</span> {
         <span class="comment">// Draw pixmap in device coordinates to avoid pixmap scaling;</span>
         <span class="keyword">const</span> <span class="type"><a href="qpixmap.html">QPixmap</a></span> pixmap <span class="operator">=</span> sourcePixmap(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>DeviceCoordinates<span class="operator">,</span> <span class="operator">&amp;</span>offset);
         painter<span class="operator">-</span><span class="operator">&gt;</span>setWorldTransform(<span class="type"><a href="qtransform.html">QTransform</a></span>());
         <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
         painter<span class="operator">-</span><span class="operator">&gt;</span>drawPixmap(offset<span class="operator">,</span> pixmap);
     }
     <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 }
</pre>
<p>This function should not be called explicitly by the user, since
it is meant for reimplementation purposes only.</p>


<h3 class="fn"><a name="drawSource" />QGraphicsEffect.drawSource (<i>self</i>, <a href="qpainter.html">QPainter</a>&#160;<i>painter</i>)</h3><p>Draws the source directly using the given <i>painter</i>.</p>
<p>This function should only be called from <a href="qgraphicseffect.html#draw">QGraphicsEffect.draw</a>().</p>
<p>For example:</p>
<pre class="cpp">
 MyGraphicsOpacityEffect<span class="operator">.</span><a href="qgraphicseffect.html#draw">draw</a>(<span class="type"><a href="qpainter.html">QPainter</a></span> <span class="operator">*</span>painter)
 {
     <span class="comment">// Fully opaque; draw directly without going through a pixmap.</span>
     <span class="keyword">if</span> (<a href="qmatrix.html#qFuzzyCompare">qFuzzyCompare</a>(m_opacity<span class="operator">,</span> <span class="number">1</span>)) {
         drawSource(painter);
         <span class="keyword">return</span>;
     }
     <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 }
</pre>
<p><b>See also</b> <a href="qgraphicseffect.html#draw">QGraphicsEffect.draw</a>().</p>


<h3 class="fn"><a name="isEnabled" />bool QGraphicsEffect.isEnabled (<i>self</i>)</h3><h3 class="fn"><a name="setEnabled" />QGraphicsEffect.setEnabled (<i>self</i>, bool&#160;<i>enable</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setEnabled(bool)</tt>.</p><h3 class="fn"><a name="sourceBoundingRect" /><a href="qrectf.html">QRectF</a> QGraphicsEffect.sourceBoundingRect (<i>self</i>, <a href="qt.html#CoordinateSystem-enum">Qt.CoordinateSystem</a>&#160;<i>system</i>&#160;=&#160;Qt.LogicalCoordinates)</h3><p>Returns the bounding rectangle of the source mapped to the given
<i>system</i>.</p>
<p>Calling this function with <a href="qt.html#CoordinateSystem-enum">Qt.DeviceCoordinates</a> outside
of <a href="qgraphicseffect.html#draw">QGraphicsEffect.draw</a>()
will give undefined results, as there is no device context
available.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#draw">draw</a>().</p>


<h3 class="fn"><a name="sourceChanged" />QGraphicsEffect.sourceChanged (<i>self</i>, <a href="qgraphicseffect-changeflags.html">ChangeFlags</a>&#160;<i>flags</i>)</h3><p>This virtual function is called by <a href="qgraphicseffect.html">QGraphicsEffect</a> to notify the effect
that the source has changed. If the effect applies any cache, then
this cache must be purged in order to reflect the new appearance of
the source.</p>
<p>The <i>flags</i> describes what has changed.</p>


<h3 class="fn"><a name="sourceIsPixmap" />bool QGraphicsEffect.sourceIsPixmap (<i>self</i>)</h3><p>Returns true if the source effectively is a pixmap, e.g., a
<a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>.</p>
<p>This function is useful for optimization purposes. For instance,
there's no point in drawing the source in device coordinates to
avoid pixmap scaling if this function returns true - the source
pixmap will be scaled anyways.</p>


<h3 class="fn"><a name="sourcePixmap" />(<a href="qpixmap.html">QPixmap</a>, <a href="qpoint.html">QPoint</a>&#160;<i>offset</i>) QGraphicsEffect.sourcePixmap (<i>self</i>, <a href="qt.html#CoordinateSystem-enum">Qt.CoordinateSystem</a>&#160;<i>system</i>&#160;=&#160;Qt.LogicalCoordinates, <a href="qgraphicseffect.html#PixmapPadMode-enum">PixmapPadMode</a>&#160;<i>mode</i>&#160;=&#160;QGraphicsEffect.PadToEffectiveBoundingRect)</h3><p>Returns a pixmap with the source painted into it.</p>
<p>The <i>system</i> specifies which coordinate system to be used
for the source. The optional <i>offset</i> parameter returns the
offset where the pixmap should be painted at using the current
painter. For control on how the pixmap is padded use the
<i>mode</i> parameter.</p>
<p>The returned pixmap is clipped to the current painter's device
rectangle when <i>system</i> is <a href="qt.html#CoordinateSystem-enum">Qt.DeviceCoordinates</a>.</p>
<p>Calling this function with <a href="qt.html#CoordinateSystem-enum">Qt.DeviceCoordinates</a> outside
of <a href="qgraphicseffect.html#draw">QGraphicsEffect.draw</a>()
will give undefined results, as there is no device context
available.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#draw">draw</a>()
and <a href="qgraphicseffect.html#boundingRect">boundingRect</a>().</p>


<h3 class="fn"><a name="update" />QGraphicsEffect.update (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void update()</tt>.</p><p>Schedules a redraw of the effect. Call this function whenever
the effect needs to be redrawn. This function does not trigger a
redraw of the source.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a>().</p>


<h3 class="fn"><a name="updateBoundingRect" />QGraphicsEffect.updateBoundingRect (<i>self</i>)</h3><p>This function notifies the effect framework when the effect's
bounding rectangle has changed. As a custom effect author, you must
call this function whenever you change any parameters that will
cause the virtual <a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a>()
function to return a different value.</p>
<p>This function will call <a href="qgraphicseffect.html#update">update</a>() if this is
necessary.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a>(),
<a href="qgraphicseffect.html#boundingRect">boundingRect</a>(), and
<a href="qgraphicseffect.html#sourceBoundingRect">sourceBoundingRect</a>().</p>
<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="enabledChanged" />void enabledChanged (bool)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the effect is enabled or
disabled. The <i>enabled</i> parameter holds the effects's new
enabled state.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#enabled-prop">isEnabled</a>().</p>


<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>